package com.jmb.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmb.api.common.utils.IPutil;
import com.jmb.api.model.entity.UserLoginLog;
import com.jmb.api.service.UserLoginLogService;
import com.jmb.api.mapper.UserLoginLogMapper;
import com.jmb.api.vo.system.UserLoginLogDao;
import com.jmb.api.vo.system.UserLoginLogVo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author jinbo
* @description 针对表【user_login_log】的数据库操作Service实现
* @createDate 2025-04-08 13:53:56
*/
@Service
public class UserLoginLogServiceImpl extends ServiceImpl<UserLoginLogMapper, UserLoginLog>
    implements UserLoginLogService{

    @Autowired
    private UserLoginLogMapper userLoginLogMapper;



    @Override
    public IPage<UserLoginLogDao> getLoginLogList(IPage<UserLoginLogDao> page, UserLoginLogVo userLoginLogVo) {
        return userLoginLogMapper.LogList(page,userLoginLogVo);
    }

    @Override
    public String getUserIp(HttpServletRequest request) {
        IPutil iPutil = new IPutil();
        String[] headers = {"x-forwarded-for", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR", "X-Real-IP"};
        for (String header : headers){
            String ip = iPutil.getHeader(request, header);
            if (ip!=null && iPutil.isUnKnow(ip)){
                return iPutil.extractFirstIp(ip);
            }
        }
        return request.getRemoteAddr();
    }

    @Override
    public void insertLoginLog(UserLoginLogDao userLoginLogDao) {
         userLoginLogMapper.insert(userLoginLogDao);
    }
}




